package com.kele.utils;//package com.two.domain;


import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;

/**
 * 自定义的返回数据类
 * @param <T>
 *            @JsonSerialize 表示值为null的时候，key会消失
 */
@Data
@ToString
@NoArgsConstructor
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@ApiModel(description = "返回响应数据")
public class ResponseData<T> implements Serializable {

     //状态码：0-成功，1-失败
    @ApiModelProperty(value = "状态码")
    private int code;


    //提示消息，如果成功可为空或SUCCESS
    @ApiModelProperty(value = "提示信息")
    private String msg;


     //返回结果数据
    @ApiModelProperty(value = "返回数据对象")
    private T data;


    public static ResponseData success(String msg) {
        return success(msg,null);
    }

    public static ResponseData success(String msg,Object data) {
        ResponseData result = new ResponseData();
        result.setCode(0);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static ResponseData fail(String msg) {
        ResponseData result=new ResponseData();
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    public static ResponseData fail(String msg, Object data) {
        ResponseData result = new ResponseData();
        result.setCode(1);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}